﻿using System;
using System.Windows.Forms;
using S7PlcDataManager.Controls;
using S7PlcDataManager.Tools;
using ZbSkin.Frm;

namespace S7PlcDataManager
{
    public partial class FormMain : SkinMainForm
    {
        public FormMain()
        {
            InitializeComponent();

            ContentPanel.Controls.Add(new MainControl() {Width = Constants.ContentWidth});
            BottomPanel.Controls.Add(new BottomControl() {Dock = DockStyle.Fill});

            ContentPanel.SizeChanged += OnContentPanelSizeChanged;

            //TODO: 减去主页面多余的高度
            //Height -= 78;
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            EnableMaxButton = false;
            Title = "西门子S7系列PLC数据管理工具";
            ChangeContentPanelControls();
        }

        private void OnContentPanelSizeChanged(object sender, EventArgs e)
        {
            ChangeContentPanelControls();
        }

        private void ChangeContentPanelControls()
        {
            foreach (Control control in ContentPanel.Controls)
            {
                if (control != null)
                {
                    control.Height = ContentPanel.ClientSize.Height - 20;
                    control.Left = (ContentPanel.ClientSize.Width - control.Width) / 2;
                    control.Top = 10;
                }
            }
        }
    }
}
